package com.wf.atm.pojo;

import lombok.Data;
import lombok.NoArgsConstructor;
import com.wf.atm.exception.ATMException;
import com.wf.atm.exception.BalanceNotEnoughException;

import java.io.Serializable;
import java.util.Objects;

/**
 * 账户
 *
 * @author mpk
 * @since 2024/6/3 18:02:42
 *
 */

@Data
@NoArgsConstructor
public abstract class Account implements Serializable {


    private static final long serialVersionUID = 4257605692809595675L;
    /**
     *
     * 账户号码
     */
    private Long id;
    /**
     * 账户密码
     */
    private String password;
    /**
     * 真实姓名
     */
    private String name;
    /**
     * 身份证号码
     */
    private String personId;
    /**
     * 地址
     */
    private String address;
    /**
     * 客户的电子邮箱
     */
    private String email;
    /**
     * 账户余额
     */
    private double balance;


    /**
     * 存款
     *
     * @param money 存款金额
     * @return 账户
     */

    public Account deposit(double money) throws ATMException {
        if(money<=0)
        {
            throw  new ATMException("存款金额不能为负数！");
        }
        this.balance = this.balance + money;
        return this;

    }

    /**
     * 取款
     *
     * @param balance 取款金额
     * @return 账户
     */

    public abstract Account withdraw(double balance)  throws BalanceNotEnoughException;

    public Account(Long id, String password, String name, String personId,String address, String email) {



        this.id = id;
        this.password = password;
        this.name = name;
        this.personId = personId;
        this.address = address;
        this.email = email;

    }
/*    方法:
    deposit:  存款方法,参数类型：double, 返回类型：Account
    withdraw:取款方法,参数类型：double, 返回类型：Account

    构造方法:
    有参和无参,有参构造方法用于设置必要的属性*/

    @Override
    public String toString() {
        return "Account{" +
                "id=" + id +
                ", password='" + password + '\'' +
                ", name='" + name + '\'' +
                ", personId='" + personId + '\'' +
                ", email='" + email + '\'' +
                ", balance=" + balance +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Account account = (Account) o;
        return Objects.equals(name, account.name) && Objects.equals(personId, account.personId);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, personId);
    }
}
